************************************
* POWER CALCULATIONS
************************************

preserve
gen classx_ext = !missing(ssc_final)
la var classx_ext "Any Exam?"
gen sample = ssc_count == 6

foreach var of varlist ssc_* {
	*standardizing the distribution
	qui summ `var' if treatment == 0
	gen z`var' = (`var' - r(mean))/r(sd)
	gen pc_`var' = `var' 

}
replace pc_ssc_final = ssc_final/500 *100



la var read_std "Std. ASER: Reading"
la var math_std "Std. ASER: Math"

la var classx_ext "Any Exam?"
la var pc_ssc_tamil "Class X: Tamil"
la var pc_ssc_english "Class X: English"
la var pc_ssc_maths "Class X: Maths"
la var pc_ssc_science "Class X: Science"
la var pc_ssc_ssc "Class X: Social Science"
la var pc_ssc_final "Class X: Total"

la var ps "Index of Parental Support"

*Effect size in the control and treatment
foreach var of varlist ssc_* {
	qui summ pc_`var' if treatment == 0 
	gen std_`var' = pc_`var'/`r(sd)'
}




*Generating the graphs and details
global min_mde = 0.1
global d = 0.01
global pts = 145
global max_mde = $min_mde + $pts*$d
di ${max_mde}

local varlist "${baseoutcomes_std} classx_ext ${xthmarks} ps"



ds `varlist'
local varcount: word count `r(varlist)'
mat A = J(`varcount', 2, .)
 
local col = 0

foreach var of varlist `varlist' {
*	local var "pc_ssc_final"

	local rownames "`rownames' "`: var label `var'' \" "
	local col = `col' + 1

	cap drop std 

	qui summ `var' if treatment == 0 
	global sd_control = `r(sd)'
	gen std = `var'/`r(sd)'

	qui summ std if treatment == 0 
	global cmean = `r(mean)'

 	qui loneway `var'  id_school
 	global rho = `r(rho)'

 	forval i = 1/145 {
	*local i = 0.05
		local dval =${min_mde} + (`i'-1)* $d
		qui power twomeans ${cmean}, diff(`dval') m1(40) m2(40) rho(${rho})

		if `r(K1)' == 12 {
			mat A[`col',1] = `dval'
			mat A[`col',2] = `dval'* ${sd_control}
		}

	}
}
mat list A 

frmttable using "$tables/TableC3.tex", statmat(A) sdec(2, 2) ///
	ctitle(" " "Outcome" "MDE" "Min. Coeff.") ///
	rtitle("`rownames'") ///
	replace tex pretext(" ")
restore



